<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;


class BillModel extends Model
{
    use SoftDelete;

    // 表名
    protected $name = 'bill';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'datetime';

    protected $dateFormat = 'Y-m-d H:i:s';

    // 追加属性
    protected $append = [

    ];


    public function getTypeList()
    {
        return [
            1 => '租金',
            2 => '押金',
            3 => '水费',
            4 => '电费',
            5 => '燃气费',
            6 => '热水费',
        ];
    }

    public function getStatusList()
    {
        return [0 => '待审核', 1 => '待支付', 2 => '已支付'];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : ($data['status'] ?? '');
        $list = $this->getStatusList();
        return $list[$value] ?? '';
    }

    public function contract()
    {
        return $this->belongsTo('app\common\model\Contract', 'contract_id', 'id');
    }

    public function delUser()
    {
        return $this->belongsTo(\app\common\model\User::class, 'del_uid', 'id')->bind('username');
    }

    public function getDeleteTimeTextAttr($value, $data)
    {
        $value = $value ? $value : ($data['delete_time'] ?? '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

}
